/*
 * $Id: PrimaryKey.groovy 87 2009-02-10 19:57:53Z andre.winkler@web.de $
 * ============================================================================
 * Project groovy-oracle
 * Copyright (c) 2008 by Andre Winkler. All rights reserved.
 * ============================================================================
 *          GNU LESSER GENERAL PUBLIC LICENSE
 *  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

package de.gluehloch.groovy.oracle.meta

/**
 * Informationen �ber den Prim�rschl�ssel in einer Oracle-Datenbank.
 */
class PrimaryKey {

    String name;
    def columnNames = [];

    /**
     * Liefert eine kommaseparierte Aufzählung aller Spalten.
     * Z.B: attr1, attr2, ..., attrN
     */
    def toColumnList() {
        columnNames.join(", ")
    }

    /**
     * Kopiert die Eigenschaften von diesem Objekt in ein neue erstelltes
     * Objekt 'PrimaryKey'
     *
     * @return Ein geclonter PrimaryKey.
     */
    def copy() {
        def primaryKey = new PrimaryKey(name: name)

        def columnNames2 = []
        columnNames.each { columnNames2 << it }

        primaryKey.columnNames = columnNames2

        return primaryKey
    }

    boolean equals(def object) {
        if (!(object instanceof PrimaryKey)) {
            return false
        }

        def result = true
        result = result && (name == object.name)
        result = result && (columnNames == object.columnNames)

        return result
    }

}
